<template>
    <view class="pub_page pub_mine_bg">
        <pub-head headerName="mine_bg" :headerConfig="headerConfig"></pub-head>
        <div class="page_box page_box_scroll" :style="{ 'height': `calc(100vh - ${headerHeight})` }">
            <div class="lis_div">
                <div class="li" v-for="(li, key) in bg_img_list" :key="key" @click="bg_img = li">
                    <img class="img" :src="li">
                    <img v-if="bg_img == li" class="icon"
                        src="https://sppcp-1322907932.cos.ap-beijing.myqcloud.com/app/img_49.png">
                </div>
            </div>
            <div class="pub_btns">
                <div class="pub_btn" @click="toSave">确定</div>
            </div>
        </div>
    </view>
</template>

<script>
export default {
    data() {
        return {
            headerConfig: {
                title: '背景配置',//标题栏内容
                header_color: '#fff'
            },
            headerHeight: getApp().globalData.headerHeight,
            bg_img: '',
            bg_img_list: ['https://sppcp-1322907932.cos.ap-beijing.myqcloud.com/app/img_6.png', 'https://sppcp-1322907932.cos.ap-beijing.myqcloud.com/app/img_63.png']
        };
    },
    onLoad() {
        let img;
        if (this.$store.state.standing == 'user') {
            const bg_user = uni.getStorageSync('bg_user');
            img = bg_user ? bg_user : this.$store.state.bg_normal_user;
        } else if (this.$store.state.standing == 'manage') {
            const bg_manage = uni.getStorageSync('bg_manage');
            img = bg_manage || this.$store.state.bg_normal_manage;
        }
        this.bg_img = img;
    },
    methods: {
        toSave() {
            if (this.$store.state.standing == 'user') {
                uni.setStorageSync('bg_user', this.bg_img);
            } else if (this.$store.state.standing == 'manage') {
                uni.setStorageSync('bg_manage', this.bg_img);
            }
            this.$comFun.toast('设置成功');
        }
    },
};
</script>

<style lang="scss" scoped>
@import "@/common/css/mine.scss";
</style>
